import static java.lang.Thread.sleep;

public class Thread2 {
    static Object a = new Object();
    static Object b = new Object();

    public static void main(String[] args) {
        Thread thread1 =  new Thread(()->{
            synchronized(a){
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (b){
                    System.out.println("死锁");
                }
            }
        });
        Thread thread2 = new Thread(()->{
            synchronized (b){
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (a){
                    System.out.println("死锁");
                }
            }
        });
        thread1.start();
        thread2.start();
    }
}
